package 力扣;

/**
 * @author yyq
 * @create 2022-04-15 15:16
 */
public class leetcode700 {
    public TreeNode searchBST(TreeNode root, int val) {
      TreeNode node = preOrder(root,val);
      return node;
    }

    private TreeNode preOrder(TreeNode root, int val) {
        if (root==null) return null;
        if(root.val == val) return root;
        TreeNode node = null;
        if(root.left!=null){
            node = preOrder(root.left,val);
        }
        if(node!=null){
            return node;
        }
        if(root.right!=null){
            node = preOrder(root.right,val);
        }
        if(node!=null){
            return node;
        }
        return null;

    }

}
